<html>
<head><meta charset="utf-8"><title>DepConstructor and define_queries! · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html">DepConstructor and define_queries!</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222135164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135164">(Jan 08 2021 at 22:36)</a>:</h4>
<p><span class="user-mention" data-user-id="248906">@cjgillot</span> so, I finally got around to following up on <a href="https://github.com/rust-lang/rust/pull/80325#discussion_r548492704">https://github.com/rust-lang/rust/pull/80325#discussion_r548492704</a>. While refactoring that, I thought of making <code>DepConstructor</code> crate-private, since it's only used in rustc_middle, and I discovered that hundreds of functions are being compiled that are completely unused.</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code><span class="gh">diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs</span>
<span class="gh">index d954c8ab5fb..ff696f84332 100644</span>
<span class="gd">--- a/compiler/rustc_middle/src/dep_graph/dep_node.rs</span>
<span class="gi">+++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs</span>
<span class="gu">@@ -172,7 +172,7 @@ pub fn has_params(&amp;self) -&gt; bool {</span>
             }
         }

<span class="gd">-        pub struct DepConstructor;</span>
<span class="gi">+        crate struct DepConstructor;</span>

         #[allow(non_camel_case_types)]
         impl DepConstructor {
<span class="gh">diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs</span>
<span class="gh">index 728bfef9f46..303ad19a618 100644</span>
<span class="gd">--- a/compiler/rustc_middle/src/dep_graph/mod.rs</span>
<span class="gi">+++ b/compiler/rustc_middle/src/dep_graph/mod.rs</span>
<span class="gu">@@ -15,7 +15,8 @@</span>
     WorkProduct, WorkProductId,
 };

<span class="gd">-pub use dep_node::{label_strs, DepConstructor, DepKind, DepNode, DepNodeExt};</span>
<span class="gi">+pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};</span>
<span class="gi">+crate use dep_node::DepConstructor;</span>

 pub type DepGraph = rustc_query_system::dep_graph::DepGraph&lt;DepKind&gt;;
 pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps&lt;DepKind&gt;;
</code></pre></div>
<div class="codehilite"><pre><span></span><code>warning: associated function is never used: `normalize_opaque_types`
    --&gt; compiler/rustc_middle/src/dep_graph/dep_node.rs:182:17
     |
106  | /   macro_rules! define_dep_nodes {
107  | |       (&lt;$tcx:tt&gt;
108  | |       $(
109  | |           [$($attrs:tt)*]
...    |
182  | |                   pub fn $variant(_tcx: TyCtxt&lt;&#39;_&gt;, $(arg: $tuple_arg_ty)*) -&gt; DepNode {
     | |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...    |
300  | |       );
301  | |   }
     | |___- in this expansion of `define_dep_nodes!` (#2)
302  |
303  | /   rustc_dep_node_append!([define_dep_nodes!][ &lt;&#39;tcx&gt;
304  | |       // We use this for most things when incr. comp. is turned off.
305  | |       [] Null,
306  | |
...    |
312  | |       [] CompileCodegenUnit(Symbol),
313  | |   ]);
     | |_____- in this macro invocation (#1)
     |
    ::: compiler/rustc_middle/src/query/mod.rs:37:1
     |
37   |   / rustc_queries! {
38   |   |     Other {
39   |   |         query trigger_delay_span_bug(key: DefId) -&gt; () {
40   |   |             desc { &quot;trigger a delay span bug&quot; }
...      |
1670 |   |     }
1671 |   | }
     |   | -
     |   | |
     |   |_in this expansion of `rustc_dep_node_append!` (#1)
     |     in this macro invocation (#2)

warning: 235 warnings emitted
</code></pre></div>



<a name="222135205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135205">(Jan 08 2021 at 22:37)</a>:</h4>
<p>clearly these can't be completely deleted because <code>hir_crate</code> for example is used quite a lot, so my thought is that the same functions are being compiled multiple times in different namespaces?</p>



<a name="222135387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135387">(Jan 08 2021 at 22:39)</a>:</h4>
<p>in fact the only time I see DepConstructor used at <em>all</em> is</p>
<div class="codehilite"><pre><span></span><code>&gt; rg DepConstructor:: compiler/
compiler/rustc_middle/src/mir/mono.rs
365:        DepConstructor::CompileCodegenUnit(tcx, self.name())
</code></pre></div>



<a name="222135457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135457">(Jan 08 2021 at 22:40)</a>:</h4>
<p>which makes me think we might be able to get rid of it</p>



<a name="222135562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135562">(Jan 08 2021 at 22:41)</a>:</h4>
<p>Welcome to the query system, with its 237 queries, and 236 special cases <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="222135573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135573">(Jan 08 2021 at 22:41)</a>:</h4>
<p>Joke aside, we should totally get rid of it.</p>



<a name="222135617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135617">(Jan 08 2021 at 22:42)</a>:</h4>
<p>do you know what this is actually doing? What is <code>DepNode::construct</code>?</p>



<a name="222135673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135673">(Jan 08 2021 at 22:43)</a>:</h4>
<p><code>DepNode::construct</code> is the constructor for <code>DepNode</code>. It's not called <code>new</code>, probably for historical reasons.</p>



<a name="222135698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135698">(Jan 08 2021 at 22:43)</a>:</h4>
<p>Defined in <code>rustc_query_system/src/dep_graph/dep_node.rs</code></p>



<a name="222135709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135709">(Jan 08 2021 at 22:43)</a>:</h4>
<p>ok, so I could replace all the DepConstructor nonsense with something like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">codegen_dep_node</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">tcx</span>: <span class="nc">TyCtxt</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">DepNode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">DepNode</span>::<span class="n">construct</span><span class="p">(</span><span class="n">tcx</span><span class="p">,</span><span class="w"> </span><span class="n">DepKind</span>::<span class="n">CompileCodegenUnit</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">names</span><span class="p">())</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222135835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135835">(Jan 08 2021 at 22:45)</a>:</h4>
<p>One caveat: <code>DepNode::construct</code> does not check that the key type corresponds to the query definition. That is <code>DepConstructor</code>'s job.</p>



<a name="222135865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135865">(Jan 08 2021 at 22:45)</a>:</h4>
<p>Replacing the whole <code>DepConstructor</code> macro by just the few useful functions could be enough.</p>



<a name="222135880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135880">(Jan 08 2021 at 22:45)</a>:</h4>
<p>omg it was literally that easy</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code><span class="gh">diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs</span>
<span class="gh">index 1e70f760504..243d0aa5fa5 100644</span>
<span class="gd">--- a/compiler/rustc_middle/src/mir/mono.rs</span>
<span class="gi">+++ b/compiler/rustc_middle/src/mir/mono.rs</span>
<span class="gu">@@ -362,7 +362,8 @@ fn item_sort_key&lt;'tcx&gt;(tcx: TyCtxt&lt;'tcx&gt;, item: MonoItem&lt;'tcx&gt;) -&gt; ItemSortKey&lt;'</span>
     }

     pub fn codegen_dep_node(&amp;self, tcx: TyCtxt&lt;'tcx&gt;) -&gt; DepNode {
<span class="gd">-        DepConstructor::CompileCodegenUnit(tcx, self.name())</span>
<span class="gi">+        use crate::dep_graph::DepKind;</span>
<span class="gi">+        DepNode::construct(tcx, DepKind::CompileCodegenUnit, &amp;self.name())</span>
     }
 }
</code></pre></div>
<div class="codehilite"><pre><span></span><code>warning: struct is never constructed: `DepConstructor`
    --&gt; compiler/rustc_middle/src/dep_graph/dep_node.rs:175:9
</code></pre></div>



<a name="222135938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135938">(Jan 08 2021 at 22:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222135835">said</a>:</p>
<blockquote>
<p>One caveat: <code>DepNode::construct</code> does not check that the key type corresponds to the query definition. That is <code>DepConstructor</code>'s job.</p>
</blockquote>
<p>I don't know what this means</p>



<a name="222135946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135946">(Jan 08 2021 at 22:46)</a>:</h4>
<p>is 'type' not encoded in the type system?</p>



<a name="222135988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222135988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222135988">(Jan 08 2021 at 22:47)</a>:</h4>
<p><code>DepNode::construct</code> does not know that <code>CompileCodegenUnit</code> takes <code>Symbol</code>s as keys.</p>



<a name="222136084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136084">(Jan 08 2021 at 22:48)</a>:</h4>
<p>If you call <code>DepNode::construct(tcx, DepKind::CompileCodegenUnit, some_def_id)</code>, the compiler will not yell at you.</p>



<a name="222136104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136104">(Jan 08 2021 at 22:48)</a>:</h4>
<p>oh I see, <code>construct</code> is generic and there's no checks that you instantiate it with the right type</p>



<a name="222136136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136136">(Jan 08 2021 at 22:49)</a>:</h4>
<p>I'm still inclined to get rid of DepConstructor and just leave a comment that it's important to get the type right</p>



<a name="222136318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136318">(Jan 08 2021 at 22:51)</a>:</h4>
<p>I rather replace it by</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">make_compile_codegen_unit</span><span class="p">(</span><span class="n">tcx</span>: <span class="nc">TyCtxt</span><span class="o">&lt;'</span><span class="nb">_</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">name</span>: <span class="nc">Symbol</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">DepNode</span>::<span class="n">construct</span><span class="p">(</span><span class="n">tcx</span><span class="p">,</span><span class="w"> </span><span class="n">DepKind</span>::<span class="n">CompileCodegenUnit</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>in <code>dep_node.rs</code>, with a by warning comment linking it to the definition of <code>CompileCodegenUnit</code>.</p>



<a name="222136372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136372">(Jan 08 2021 at 22:52)</a>:</h4>
<p>ok, I'll do that</p>



<a name="222136383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222136383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222136383">(Jan 08 2021 at 22:52)</a>:</h4>
<p>And vice versa <span aria-label="music" class="emoji emoji-1f3b5" role="img" title="music">:music:</span></p>



<a name="222137049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222137049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222137049">(Jan 08 2021 at 23:01)</a>:</h4>
<p>Full disclosure: <a href="https://github.com/rust-lang/rust/issues/78452">#78452</a> made <code>DepConstructor</code> a module, named <code>dep_constructor</code>.</p>



<a name="222137175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222137175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222137175">(Jan 08 2021 at 23:02)</a>:</h4>
<p>oh lol what timing</p>



<a name="222137468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222137468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222137468">(Jan 08 2021 at 23:05)</a>:</h4>
<p>wow, rebasing came up with a <em>lot</em> of unused imports lol</p>



<a name="222137868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222137868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222137868">(Jan 08 2021 at 23:10)</a>:</h4>
<p><span class="user-mention" data-user-id="248906">@cjgillot</span> what is <code>DepKindStruct</code> for?</p>



<a name="222137893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222137893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222137893">(Jan 08 2021 at 23:11)</a>:</h4>
<p>I see that it delegates almost everything to <code>query_keys::$variant as DepNodeParams</code></p>



<a name="222138154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138154">(Jan 08 2021 at 23:14)</a>:</h4>
<p>It provides a unified place for the description of all <code>DepKind</code>s. Among them, the description of the query itself (is_anon, is_eval_always), and the way the dep-graph should invoke it (<code>force_from_dep_node</code> and <code>try_load_from_on_disk_cache</code>).</p>



<a name="222138226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138226">(Jan 08 2021 at 23:15)</a>:</h4>
<p><code>DepNodeParams</code> only serves to convert a <code>Fingerprint</code> into a query key, effectively reversing <code>DepNode::construct</code>.</p>



<a name="222138266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138266">(Jan 08 2021 at 23:15)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="sd">/// Contains variant =&gt; str representations for constructing</span>
<span class="w">        </span><span class="sd">/// DepNode groups for tests.</span>
<span class="w">        </span><span class="cp">#[allow(dead_code, non_upper_case_globals)]</span><span class="w"></span>
<span class="w">        </span><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">label_strs</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">           </span><span class="cp">$(</span><span class="w"></span>
<span class="w">                </span><span class="k">pub</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="cp">$variant</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="fm">stringify!</span><span class="p">(</span><span class="cp">$variant</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="p">)</span><span class="o">*</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>does that mean I can make this and <code>dep_kind_from_label_string</code> <code>#[cfg(test)]</code>?</p>



<a name="222138389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138389">(Jan 08 2021 at 23:17)</a>:</h4>
<p>Those are used in rustc_incremental, for the incremental test suite.</p>



<a name="222138471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138471">(Jan 08 2021 at 23:18)</a>:</h4>
<p>There is a pair of attributes (rustc_clean/rustc_dirty) which check the color of some dep nodes.</p>



<a name="222138487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138487">(Jan 08 2021 at 23:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222138389">said</a>:</p>
<blockquote>
<p>Those are used in rustc_incremental, for the incremental test suite.</p>
</blockquote>
<p>could we get cargo to pass <code>--cfg test</code> to rustc_middle too?</p>



<a name="222138536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138536">(Jan 08 2021 at 23:19)</a>:</h4>
<p>no, that won't work, the test suite is run with a normal compiler, it's not unit tests</p>



<a name="222138553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138553">(Jan 08 2021 at 23:19)</a>:</h4>
<p>I guess in theory we could gate it for dist compiles but seems pretty unnecessary</p>



<a name="222138556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138556">(Jan 08 2021 at 23:19)</a>:</h4>
<p>ok, could we run the test suite with <code>--cfg test</code>? :P</p>



<a name="222138565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138565">(Jan 08 2021 at 23:19)</a>:</h4>
<p>oh yeah I guess that doesn't actually help bootstrap times</p>



<a name="222138635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138635">(Jan 08 2021 at 23:20)</a>:</h4>
<p>no you don't want --cfg test</p>



<a name="222138678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138678">(Jan 08 2021 at 23:21)</a>:</h4>
<p>it just seems kind of silly to generate all those matches when they're only ever used for <code>src/test/incremental</code></p>



<a name="222138822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138822">(Jan 08 2021 at 23:23)</a>:</h4>
<p>hm? what matches?</p>



<a name="222138850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138850">(Jan 08 2021 at 23:23)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_middle/src/dep_graph/dep_node.rs#L360">https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_middle/src/dep_graph/dep_node.rs#L360</a></p>



<a name="222138898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138898">(Jan 08 2021 at 23:24)</a>:</h4>
<p>that function is only used by compiletest AFAIK</p>



<a name="222138916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138916">(Jan 08 2021 at 23:24)</a>:</h4>
<p>it is just the one match though?</p>



<a name="222138973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138973">(Jan 08 2021 at 23:25)</a>:</h4>
<p>well, and all of <code>dirty_clean</code> too</p>



<a name="222138975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138975">(Jan 08 2021 at 23:25)</a>:</h4>
<p>oh hm, I guess this is in a macro, maybe it is getting expanded multiple times? not sure?</p>



<a name="222138986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138986">(Jan 08 2021 at 23:25)</a>:</h4>
<p>Its a drop in the ocean of monomorphizations for the query system.</p>



<a name="222138988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138988">(Jan 08 2021 at 23:25)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_incremental/src/persist/dirty_clean.rs">https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_incremental/src/persist/dirty_clean.rs</a></p>



<a name="222138998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222138998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222138998">(Jan 08 2021 at 23:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222138986">said</a>:</p>
<blockquote>
<p>Its a drop in the ocean of monomorphizations for the query system.</p>
</blockquote>
<p>ok, I will direct my attention elsewhere</p>



<a name="222139045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139045">(Jan 08 2021 at 23:26)</a>:</h4>
<p>yeah this all seems fairly reasonable/straightforward</p>



<a name="222139068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139068">(Jan 08 2021 at 23:26)</a>:</h4>
<p>It should only be expanded once, the macro is a kind of callback for the <code>rustc_dep_node_append</code> macro.</p>



<a name="222139082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139082">(Jan 08 2021 at 23:26)</a>:</h4>
<p><code>rustc_dep_node_append</code> is so complicated <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="222139200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139200">(Jan 08 2021 at 23:28)</a>:</h4>
<p><span class="user-mention" data-user-id="248906">@cjgillot</span> maybe I should ask - where are all the monomorphizations happening? what would actually have an impact?</p>



<a name="222139372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139372">(Jan 08 2021 at 23:31)</a>:</h4>
<p>off the top of my head, generating 236 DepKindStructs with 4 functions each seems not great</p>



<a name="222139461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139461">(Jan 08 2021 at 23:32)</a>:</h4>
<p>more functions is much better for LLVM than small number of huge functions</p>



<a name="222139471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139471">(Jan 08 2021 at 23:32)</a>:</h4>
<p>Most of the work is on <code>{get,ensure,force}_query</code>. The generic versions are defined in <code>rustc_query_system::query::plumbing</code>. The instances are in <code>rustc_middle::dep_graph::dep_node</code> (forcing), and <code>rustc_middle::ty::query::plumbing</code> (get/ensure).</p>



<a name="222139487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139487">(Jan 08 2021 at 23:32)</a>:</h4>
<p>LLVM is roughly O(n) or so on number of functions but more like n^3 or something on size of functions, obviously not real numbers :)</p>



<a name="222139498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139498">(Jan 08 2021 at 23:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222139461">said</a>:</p>
<blockquote>
<p>more functions is much better for LLVM than small number of huge functions</p>
</blockquote>
<p>right, I was hoping to make these generic functions instead so they only have to be type checked once</p>



<a name="222139543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139543">(Jan 08 2021 at 23:33)</a>:</h4>
<p>I feel like high order bit is not type checking for rustc compile times, and I'm not sure they <em>can</em> be made generic</p>



<a name="222139674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139674">(Jan 08 2021 at 23:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222139471">said</a>:</p>
<blockquote>
<p>Most of the work is on <code>{get,ensure,force}_query</code>. The generic versions are defined in <code>rustc_query_system::query::plumbing</code>. The instances are in <code>rustc_middle::dep_graph::dep_node</code> (forcing), and <code>rustc_middle::ty::query::plumbing</code> (get/ensure).</p>
</blockquote>
<p>wow, these are really big functions to be marked as <code>#[inline(always)]</code> <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> <br>
<a href="https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_query_system/src/query/plumbing.rs#L570">https://github.com/rust-lang/rust/blob/26438b473883ea607b30288e461187f0fb2fe589/compiler/rustc_query_system/src/query/plumbing.rs#L570</a></p>



<a name="222139749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139749">(Jan 08 2021 at 23:36)</a>:</h4>
<p>I'll try removing that and see if it makes any difference on perf</p>



<a name="222139752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139752">(Jan 08 2021 at 23:36)</a>:</h4>
<p>For reference, you can look at the rustc_middle line in <a href="http://gistpreview.github.io/?33d98065c10f6926afe530587575a625/before-pr80522-cargo-timing.html">http://gistpreview.github.io/?33d98065c10f6926afe530587575a625/before-pr80522-cargo-timing.html</a><br>
The blue part is HIR &amp; type checking, the purple one is LLVM codegen for (mostly) the query system.</p>



<a name="222139767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139767">(Jan 08 2021 at 23:37)</a>:</h4>
<p>Those call inline(never) functions <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="222139791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139791">(Jan 08 2021 at 23:37)</a>:</h4>
<p>still, <code>force_query_with_job</code> is 35 lines of significant code just by itself</p>



<a name="222139874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139874">(Jan 08 2021 at 23:38)</a>:</h4>
<p>About this, I already have <a href="https://github.com/rust-lang/rust/issues/78780">#78780</a> in flight.</p>



<a name="222139959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139959">(Jan 08 2021 at 23:40)</a>:</h4>
<p>ok, I'll wait until that's merged</p>



<a name="222139967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139967">(Jan 08 2021 at 23:40)</a>:</h4>
<p>Feel free to comment on it :)</p>



<a name="222139971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222139971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222139971">(Jan 08 2021 at 23:40)</a>:</h4>
<p>wow that touches a <em>lot</em> of code - should I just hold off on all of this until then?</p>



<a name="222140073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222140073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222140073">(Jan 08 2021 at 23:42)</a>:</h4>
<p>Don't feel constrained by this PR. If you have a decent workstation for perf runs (I don't), please go ahead!</p>



<a name="222140087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222140087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222140087">(Jan 08 2021 at 23:42)</a>:</h4>
<p>oh I was just going to open a PR and run <code>@rust-timer queue</code> haha</p>



<a name="222140121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222140121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222140121">(Jan 08 2021 at 23:43)</a>:</h4>
<p>The most difficult part is to avoid runtime degradation. This code is absurdly sensitive.</p>



<a name="222141606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222141606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222141606">(Jan 09 2021 at 00:05)</a>:</h4>
<p>About rustc_middle compile time, I have <a href="https://github.com/rust-lang/rust/issues/70951">#70951</a> in flight. Unfortunately, there is a significant runtime regression (up to 7%), which I am still trying to mitigate.</p>



<a name="222224554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222224554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222224554">(Jan 10 2021 at 14:27)</a>:</h4>
<p>So I recently saw the following comment: <a href="https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/compiler/rustc_query_system/src/dep_graph/dep_node.rs#L66">https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/compiler/rustc_query_system/src/dep_graph/dep_node.rs#L66</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="c1">// FIXME: Enforce this by preventing manual construction of `DefNode`</span>
<span class="w">    </span><span class="c1">// (e.g. add a `_priv: ()` field)</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">hash</span>: <span class="nc">PackedFingerprint</span><span class="p">,</span><span class="w"></span>
</code></pre></div>
<p>and I tried adding a <code>pub(crate)</code> field, but it turns out rustc_middle is actually using this:</p>
<div class="codehilite"><pre><span></span><code>error: cannot construct `rustc_query_system::dep_graph::DepNode&lt;dep_node::DepKind&gt;` with struct literal syntax due to inaccessible fields
    --&gt; compiler/rustc_middle/src/dep_graph/dep_node.rs:237:17
     |
106  | /   macro_rules! define_dep_nodes {
107  | |       (&lt;$tcx:tt&gt;
108  | |       $(
109  | |           [$($attrs:tt)*]
...    |
237  | |                   DepNode {
     | |                   ^^^^^^^
...    |
300  | |       );
301  | |   }
     | |___- in this expansion of `define_dep_nodes!` (#2)
</code></pre></div>
<p><a href="https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/compiler/rustc_middle/src/dep_graph/dep_node.rs#L432">https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/compiler/rustc_middle/src/dep_graph/dep_node.rs#L432</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="sd">/// Construct a DepNode from the given DepKind and DefPathHash. This</span>
<span class="w">    </span><span class="sd">/// method will assert that the given DepKind actually requires a</span>
<span class="w">    </span><span class="sd">/// single DefId/DefPathHash parameter.</span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">from_def_path_hash</span><span class="p">(</span><span class="n">def_path_hash</span>: <span class="nc">DefPathHash</span><span class="p">,</span><span class="w"> </span><span class="n">kind</span>: <span class="nc">DepKind</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">DepNode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="fm">debug_assert!</span><span class="p">(</span><span class="n">kind</span><span class="p">.</span><span class="n">can_reconstruct_query_key</span><span class="p">()</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">kind</span><span class="p">.</span><span class="n">has_params</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="n">DepNode</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">kind</span><span class="p">,</span><span class="w"> </span><span class="n">hash</span>: <span class="nc">def_path_hash</span><span class="p">.</span><span class="mf">0.</span><span class="n">into</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Is this behavior incorrect? Or is the FIXME wrong?</p>



<a name="222225165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225165">(Jan 10 2021 at 14:42)</a>:</h4>
<p>My guess is the comment is pre-existing before the split of query system to a separate crate.</p>



<a name="222225418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225418">(Jan 10 2021 at 14:49)</a>:</h4>
<p>I added that FIXME</p>



<a name="222225436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225436">(Jan 10 2021 at 14:49)</a>:</h4>
<p>the way we register the mapping for incr comp has changed, so that may be outdated</p>



<a name="222225514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225514">(Jan 10 2021 at 14:51)</a>:</h4>
<p>ok, I'm going to leave this for people more familiar with incr-comp then <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="222225515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225515">(Jan 10 2021 at 14:51)</a>:</h4>
<p>yeah, <code>register_reused_dep_node</code> is now called from <code>register_reused_dep_nodes</code> in a single place</p>



<a name="222225516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225516">(Jan 10 2021 at 14:51)</a>:</h4>
<p>so that comment can be removed</p>



<a name="222225522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225522">(Jan 10 2021 at 14:51)</a>:</h4>
<p>originally, we did the registration when a <code>DepNode</code> was constructed</p>



<a name="222225524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225524">(Jan 10 2021 at 14:51)</a>:</h4>
<p>so it was important to keep track of all of the places where that could happen</p>



<a name="222225596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222225596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222225596">(Jan 10 2021 at 14:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125294">Aaron Hill</span> <a href="#narrow/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!/near/222225515">said</a>:</p>
<blockquote>
<p>yeah, <code>register_reused_dep_node</code> is now called from <code>register_reused_dep_nodes</code> in a single place</p>
</blockquote>
<p>What does register_reused do?</p>



<a name="222226193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226193">(Jan 10 2021 at 15:07)</a>:</h4>
<p>It ensures that we store a <code>DefPathHash -&gt; DefId</code> mapping in the incremental cache that we write out at the end of compilation</p>



<a name="222226203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226203">(Jan 10 2021 at 15:07)</a>:</h4>
<p>if the <code>DefId</code> is from a foreign crate</p>



<a name="222226213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226213">(Jan 10 2021 at 15:07)</a>:</h4>
<p>that lets us try to map the <code>DefPathHash</code> to a <code>DefId</code> in the next compilation session, without needing to decode the entire def path table for a foreign crate</p>



<a name="222226264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226264">(Jan 10 2021 at 15:08)</a>:</h4>
<p>the impementation has changed a bit, but <a href="https://github.com/rust-lang/rust/pull/74967">https://github.com/rust-lang/rust/pull/74967</a> gives an overview of how it works</p>



<a name="222226265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226265">(Jan 10 2021 at 15:08)</a>:</h4>
<p>along with comments in the code</p>



<a name="222226286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226286">(Jan 10 2021 at 15:09)</a>:</h4>
<blockquote>
<p>We then use the old DefIndex as an initial guess, which we validate by<br>
comparing the expected and actual DefPathHashes. In most cases,<br>
foreign crates will be completely unchanged, which means that we our<br>
guess will be correct. If our guess is wrong, we fall back to decoding<br>
the entire DefPathTable for the foreign crate.</p>
</blockquote>
<p>When would the guess be wrong?</p>



<a name="222226339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226339">(Jan 10 2021 at 15:10)</a>:</h4>
<p>If the <code>DefPathHash</code> still exists, but the <code>DefId</code> is different</p>



<a name="222226349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226349">(Jan 10 2021 at 15:11)</a>:</h4>
<p>e.g. if you add/remove an item that occurs before the target an item in crate, the <code>DefIndex</code> will change</p>



<a name="222226350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226350">(Jan 10 2021 at 15:11)</a>:</h4>
<p>I think I don't understand incremental well enough <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> I thought DefIds were meant to be stable across process invocations?</p>



<a name="222226354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226354">(Jan 10 2021 at 15:11)</a>:</h4>
<p>no - that's what DefPathHash is for</p>



<a name="222226356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226356">(Jan 10 2021 at 15:11)</a>:</h4>
<p>well</p>



<a name="222226360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226360">(Jan 10 2021 at 15:11)</a>:</h4>
<p>the raw contents of a DefId is just two indexes</p>



<a name="222226366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226366">(Jan 10 2021 at 15:11)</a>:</h4>
<p>ok, so the idea is that <em>if</em> you don't add more items, which is most of the time, the DefIndex won't change</p>



<a name="222226367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226367">(Jan 10 2021 at 15:11)</a>:</h4>
<p>in particular, the <code>DefIndex</code> is just a sequential identifier of definitions in the crate</p>



<a name="222226368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226368">(Jan 10 2021 at 15:11)</a>:</h4>
<p>right</p>



<a name="222226407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226407">(Jan 10 2021 at 15:12)</a>:</h4>
<p>it will also be unchanged if you add/remove items that occur 'after' the target item in the crate</p>



<a name="222226410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226410">(Jan 10 2021 at 15:12)</a>:</h4>
<p>as determined by the order in which definitions are created</p>



<a name="222226418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226418">(Jan 10 2021 at 15:12)</a>:</h4>
<p>assuming that you're only modifiying one crate, then all of the upstream crates will be unchanged</p>



<a name="222226423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226423">(Jan 10 2021 at 15:13)</a>:</h4>
<p>so any foreign <code>DefIds</code> that we save in our local incremental cache will remain valid</p>



<a name="222226435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/DepConstructor%20and%20define_queries%21/near/222226435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/DepConstructor.20and.20define_queries!.html#222226435">(Jan 10 2021 at 15:13)</a>:</h4>
<p>which lets us skip a lot of work, especially when only a few items are used from a crate</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>